#!/bin/sh

#
# You need to re-execute this script after you install new perl module(s)
# on your system.
#

HTTPD_SERVERROOT='/var/www'

echo "Put perl into chrooted apache."

#
# For core perl bianry.
#
FILES=$(ldd /usr/bin/perl | grep '/usr/' | awk '{print $NF}' | grep -v ':$')

echo "Copy libraries."
for i in ${FILES}
do
    DIR_IN_CHROOTED="${HTTPD_SERVERROOT}/$(dirname $i)/"
    mkdir -p ${DIR_IN_CHROOTED} 2>/dev/null
    cp -rf $i ${DIR_IN_CHROOTED}
done

echo "Copy binaries."
cp -f /usr/bin/perl* ${HTTPD_SERVERROOT}/usr/bin/

#
# Misc files.
#
echo "Copy misc files."

mkdir -p ${HTTPD_SERVERROOT}/etc

cp /etc/resolv.conf ${HTTPD_SERVERROOT}/etc/
cp /etc/services ${HTTPD_SERVERROOT}/etc/

mkdir -p ${HTTPD_SERVERROOT}/usr/libdata ${HTTPD_SERVERROOT}/usr/local
cp -rf /usr/libdata/perl5 ${HTTPD_SERVERROOT}/usr/libdata/

mkdir -p ${HTTPD_SERVERROOT}/usr/local/libdata
cp -rf /usr/local/libdata/perl5 ${HTTPD_SERVERROOT}/usr/local/libdata/

mkdir -p ${HTTPD_SERVERROOT}/usr/share
cp -rf /usr/share/zoneinfo ${HTTPD_SERVERROOT}/usr/share/

echo "Done."
